Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code scanning alert no. 49: Arbitrary file access during archive extraction ("Zip Slip") #368

Merged
merged 6 commits into from
Nov 18, 2024

Conversation

jkrech
Copy link
Member

@jkrech jkrech commented Oct 31, 2024

Fixes https://github.com/Open-CMSIS-Pack/cpackget/security/code-scanning/49

To fix the problem, we need to ensure that the file paths extracted from the zip archive do not contain any directory traversal sequences like ... This can be done by adding a check to ensure that the file paths are safe before using them in file operations.

  1. Add a check to ensure that the file paths do not contain .. before using them.
  2. Modify the validate method in cmd/installer/pack.go to include this check.
  3. Ensure that the utils.SecureInflateFile function is only called with sanitized paths.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…extraction ("Zip Slip")

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@jkrech jkrech requested a review from bgn42 October 31, 2024 13:29
@jkrech jkrech requested review from soumeh01 and removed request for bgn42 October 31, 2024 13:30
@jkrech
Copy link
Member Author

jkrech commented Oct 31, 2024

@bgn42 could you add a test for a pack file that uses .. as file reference to get the coverage up if you think this is useful.

Copy link
Collaborator

@soumeh01 soumeh01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Waiting for the coverage check to be passed

@soumeh01 soumeh01 marked this pull request as ready for review November 11, 2024 10:06
Copy link

codeclimate bot commented Nov 18, 2024

Code Climate has analyzed commit 42765ed and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 59.8% (0.0% change).

View more on Code Climate.

@soumeh01 soumeh01 merged commit 818916a into main Nov 18, 2024
19 checks passed
@soumeh01 soumeh01 deleted the alert-autofix-49 branch November 18, 2024 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants